import request from '@/utils/request'

/**
 * 获取权限
 * @returns
 */
export const getPermissionList = () => {
  return request({
    url: '/sys/permission'
  })
}

/**
 * 添加权限
 * @param {*} data { type: 1 为顶级 2为子级 pid: 0 为顶级 }
 * @returns
 */
export const addPermission = (data) => {
  return request({
    url: '/sys/permission',
    method: 'POST',
    data
  })
}

/**
 * 获取权限详情
 * @param {*} id
 * @returns
 */
export const getPermissionInfo = id => {
  return request({
    url: '/sys/permission/' + id
  })
}

/**
 * 编辑权限
 * @param {*} data
 * @returns
 */
export const editPermissionInfo = data => {
  return request({
    url: '/sys/permission/' + data.id,
    method: 'PUT',
    data
  })
}

export const delPermissionInfo = id => {
  return request({
    url: '/sys/permission/' + id,
    method: 'DELETE'
  })
}

/**
 * 给角色分配权限
 * @param {*} data {角色id 权限id集合}
 * @returns
 */
export const setPermissionToRole = data => {
  return request({
    url: '/sys/role/assignPrem',
    method: 'PUT',
    data
  })
}
